home *** CD-ROM | disk | FTP | other *** search
- #ifndef CP_DATA_H_
- #define CP_DATA_H_
-
- /*
- Cross-platform types & defs
-
- Written by Hiep Dam
- July 1995
- Version 1.1
- */
-
- /*
- Notes on the Cross-Platform Data types (CP_x):
-
- These data types are defined so that you can use the same data structures
- across different platforms. For example, on the Macintosh rectangles are
- defined as "Rect" while on Windows they're defined as "RECT". So porting
- from one platform to another is troublesome and lots of work. So here
- we define one "CP_Rect" which can be used for all platforms. Internally,
- they'll be defined identically to their platform-specific data structure
- counterparts. So on a Mac the CP_Rect will be internally identical to the
- Rect structure, while on Windows they'll be identical to the RECT struct.
-
- There are some caveats, however:
- 1) Don't assume the size of the structure is a certain value if
- you're writing code that you expect will be ported.
-
- In other words, don't hardcode the sizes;
- use "sizeof()" instead.
-
- For example, don't assume the size of a CP_Point is 4 bytes
- (2 shorts). On Windows 32, a CP_Point is 8 bytes (2 longs).
-
- 2) Don't assume the order of the members in the structure.
-
- On the Macintosh, v is defined before h. On Windows,
- h is defined before v. For the most part, this shouldn't
- be a problem: the only time you need to know the order
- of the members is when you're using assembly language,
- and this won't be portable anyway.
- */
-
- // ---------------------------------------------------------------------------
-
- // Platform macros
-
- #if defined(__FLAT__)
- #define __Windows32_Platform__
-
- #elif defined(_Windows)
- #define __Windows16_Platform__
-
- #elif defined(__MSDOS__)
- #define __MSDOS_Platform__
-
- #elif defined(powerc) || defined(__powerc) // PowerPC
- #define __Macintosh_Platform__
-
- #elif defined(__MWERKS__) || defined(__MC68K__) // MetroWerks
- #define __Macintosh_Platform__
-
- #elif defined(__THINK__) || defined(__SC__) // Symantec/THINK
- #define __Macintosh_Platform__
- #endif
-
-
- // Compiler macros
-
- #if defined(__Macintosh_Platform__)
- #if defined(__MWERKS__)
- #define __MetroWerks_Compiler__
- #elif defined(__THINK__) || (__SC__)
- #define __Symantec_Compiler__
- #endif
- #elif defined(__Windows16_Platform__)
- // None yet...
- #endif
-
-
- // Instruction set macros
-
- #if defined(__Macintosh_Platform__)
- #if defined(powerc) || defined(__powerc)
- #define __ISA_PowerPC__
- #else
- #define __ISA_M68K__
- #endif
- #else
- #define __ISA_x86__
- #endif
-
- // ---------------------------------------------------------------------------
-
- // Assembly macros. Currently for Macintosh only.
-
- #if defined(__Macintosh_Platform__)
-
- #if defined(__MetroWerks_Compiler__)
- #define ASM_FUNC asm
- #define ASM_BEGIN
- #define ASM_END
-
- #elif defined(__Symantec_Compiler__)
- #define ASM_FUNC
- #define ASM_BEGIN asm {
- #define ASM_END }
-
- #endif
- #endif // __Macintosh_Platform__
-
- // ---------------------------------------------------------------------------
-
- typedef signed char CP_SChar;
- typedef unsigned char CP_UChar;
-
- typedef signed short CP_SShort;
- typedef unsigned short CP_UShort;
-
- typedef signed long CP_SLong;
- typedef unsigned long CP_ULong;
-
- typedef CP_SChar CP_Char;
- typedef CP_SShort CP_Short;
- typedef CP_SLong CP_Long;
-
- // I can't understand why people use int's at all...
- typedef CP_SShort CP_SInt16;
- typedef CP_UShort CP_UInt16;
-
- typedef CP_SLong CP_SInt32;
- typedef CP_ULong CP_UInt32;
-
- // ---------------------------------------------------------------------------
-
- /*
- Windows 16 Platform (Windows 3.1)
- */
-
- #if defined(__Windows16_Platform__)
- #pragma message("Windows 16 platform version used...")
-
- typedef RECT CP_Rect;
-
- typedef POINT CP_Point_XY;
-
- typedef struct {
- int h;
- int v;
- } CP_Point_HV;
-
- typedef union {
- CP_Point_XY xy;
- CP_Point_HV hv;
- } CP_Point;
-
- typedef HRGN CP_Region_Hdl;
- typedef HWND CP_Window_Ref;
- typedef HWND CP_OutputDevice_Ref;
-
- #define nil NULL
- #define null NULL
- #define true TRUE
- #define false FALSE
-
- #define CP_Point2Point(pt) (*(POINT*)(&pt))
- #define Point2CP_Point(pt) (*(CP_Point*)(&pt))
- #define Point2CP_Point_XY(pt) (*(CP_Point_XY*)(&pt))
- #define Point2CP_Point_HV(pt) (*(CP_Point_HV*)(&pt))
-
- #define LPARAM2CP_Point(lParam, destPt) Point2CP_Point(destPt) = \
- Point2CP_Point(MAKEPOINT(lParam))
-
- // ---------------------------------------------------------------------------
-
- /*
- Windows 32 Platform (Windows 32s, Windows NT, Windows 95)
- */
-
- #elif defined(__Windows32_Platform__)
- #pragma message("Windows 32 platform version used...")
-
- typedef RECT CP_Rect;
-
- typedef POINT CP_Point_XY;
-
- typedef struct {
- long h;
- long v;
- } CP_Point_HV;
-
- typedef union {
- CP_Point_XY xy;
- CP_Point_HV hv;
- } CP_Point;
-
- typedef HRGN CP_Region_Hdl;
- typedef HWND CP_Window_Ref;
- typedef HWND CP_OutputDevice_Ref;
-
- #define nil NULL
- #define null NULL
- #define true TRUE
- #define false FALSE
-
- #define CP_Point2Point(pt) (*(POINT*)(&pt))
- #define Point2CP_Point(pt) (*(CP_Point*)(&pt))
- #define Point2CP_Point_XY(pt) (*(CP_Point_XY*)(&pt))
- #define Point2CP_Point_HV(pt) (*(CP_Point_HV*)(&pt))
-
- #define LPARAM2CP_Point(lParam, destPt) destPt.xy.x = LOWORD(lParam);\
- destPt.xy.y = HIWORD(lParam)
-
- // ---------------------------------------------------------------------------
-
- /*
- Macintosh and MS-DOS Platforms
- */
-
- #elif defined(__Macintosh_Platform__) || defined(__MSDOS_Platform__)
-
- #ifdef __MSDOS_Platform__
- #pragma message("MS-DOS platform version used...")
- #else
- //#pragma message("Macintosh platform version used...")
- #endif // __MSDOS_Platform
-
- typedef Rect CP_Rect;
-
- typedef struct {
- short y;
- short x;
- } CP_Point_XY;
-
- typedef Point CP_Point_HV;
-
- typedef union {
- CP_Point_XY xy;
- CP_Point_HV hv;
- } CP_Point;
-
- typedef RgnHandle CP_Region_Hdl;
- typedef WindowPtr CP_Window_Ref;
- typedef GDHandle CP_OutputDevice_Ref;
-
- #define CP_Point2Point(pt) (*(Point*)(&pt))
- #define Point2CP_Point(pt) (*(CP_Point*)(&pt))
- #define Point2CP_Point_XY(pt) (*(CP_Point_XY*)(&pt))
- #define Point2CP_Point_HV(pt) (*(CP_Point_HV*)(&pt))
- #endif // defined(__Macintosh_Platform__) || defined(__MSDOS_Platform__)
-
- // ---------------------------------------------------------------------------
-
- /*
- Some useful macros
- */
-
- #define CP_CopyPoint(srcPt, destPt) CP_Point2Point(destPt) = \
- CP_Point2Point(srcPt)
-
- #endif // CP_DATA_H_